#!/bin/sh
if [ -f "/config/users.txt" ]; then
    while read -r USERNAME USERID GROUP GRPID PASS; do
        grep -q "${GROUP}" /etc/group && groupmod -g "${GRPID}" "${GROUP}"
        grep -q "${GROUP}" /etc/group || groupadd -g "${GRPID}" "${GROUP}"
        useradd -M -g "${GRPID}" -u "${USERID}" -s /sbin/nologin "${USERNAME}"
        printf "%s\n%s\n" "${PASS}" "${PASS}" | passwd "${USERNAME}"
        printf "%s\n%s\n" "${PASS}" "${PASS}" | smbpasswd -s -a "${USERNAME}"
    done < /config/users.txt
fi
exec ionice -c 3 smbd -FS --configfile=/config/smb.conf --no-process-group < /dev/null
